package app.stock.client;

import java.awt.BorderLayout;
import java.util.List;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.table.TableRowSorter;

import app.common.Util;
import app.stock.common.Constants;
import app.stock.common.Stock;
import app.stock.server.StockManager;

public class SummaryPanel extends JPanel {
    StockManager sm; // @jve:decl-index=0:
    private DataTable jTable1;
    private TableRowSorter jTable1RowSorter1;

    public SummaryPanel() {
        super();
        initialize();
    }

    private void initialize() {
        sm = new StockManager();
        List stockList = sm.getStockSummaryList(null);
        Object[] tableHeaderData = new Object[] { Constants.label_sequence,
                Stock.codeLabel, Stock.nameLabel, Stock.currentPriceLabel,
                Stock.currentAmountLabel, Stock.currentMarketValueLabel,
                Stock.stockProfitWithoutCurrentMarketValueLabel,
                Stock.stockInvestmentLabel, Stock.stockProfitLabel,
                Stock.stockProfitRateLabel };
        Object[][] tableData = new Object[stockList.size()][tableHeaderData.length];
        for (int i = 0; i < stockList.size(); i++) {
            Stock stock = (Stock) stockList.get(i);
            tableData[i] = new Object[] {
                    i + 1,
                    stock.code,
                    stock.name,
                    stock.currentPrice,
                    stock.currentAmount,
                    stock.currentMarketValue,
                    Util.toFixedDigitsFloat(
                            stock.stockProfitWithoutCurrentMarketValue, 2),
                    stock.stockInvestment,
                    Util.toFixedDigitsFloat(stock.stockProfit, 2),
                    Util.toFixedDigitsFloat(stock.stockProfitRate * 100, 3)
                            + "%" };
        }
        jTable1 = new DataTable();
        jTable1.setTableData(tableHeaderData, tableData);
        jTable1.initialize();
        JScrollPane jScrollPane1 = new JScrollPane();
        jScrollPane1.setViewportView(jTable1);
        BorderLayout thisLayout = new BorderLayout();
        this.setLayout(thisLayout);
        this.add(jScrollPane1, BorderLayout.CENTER);
    }
} // @jve:decl-index=0:visual-constraint="28,-3"
